package ${packageName}.api;

<#if !isFluxDrive>
import org.apache.dubbo.config.annotation.DubboReference;
</#if>
<#if isFluxDrive>
import org.springframework.beans.factory.annotation.Autowired;
</#if>
import com.swak.annotation.Get;
import com.swak.annotation.Post;
import com.swak.annotation.RequiresPermissions;
import com.swak.annotation.RestService;
import com.swak.entity.Page;
import com.swak.entity.Parameters;
import com.swak.entity.Result;
import com.swak.security.Subject;
import ${packageName}.dto.${className}DTO;
import ${packageName}.service.${className}Service;

/**
 * ${className}Api.
 * 
 * @author Auto Generator
 * @date ${date}
 */
@RestService(path = "/api/${moduleName}/${functionName}", value = "${moduleName}${className}Api")
public class ${className}Api {

    <#if isFluxDrive>
    @Autowired
    private ${className}Service ${functionName}Service;
    <#else>
    @DubboReference
    private ${className}Service ${functionName}Service;
    </#if>

    @Get("/get")
    @RequiresPermissions("${moduleName}:${functionName}:get")
    public Result<${className}DTO> get(${className}DTO ${functionName}, Subject subject) {
        return Result.success(this.${functionName}Service.get(${functionName}.getId()));
    }
    
    @Post("/save")
    @RequiresPermissions("${moduleName}:${functionName}:save")
    public Result<${className}DTO> save(${className}DTO ${functionName}, Subject subject) {
        ${functionName}.setPrincipal(subject.getPrincipal());
        return Result.success(this.${functionName}Service.save(${functionName}));
    }
    
    @Post("/delete")
    @RequiresPermissions("${moduleName}:${functionName}:delete")
    public Result<Integer> delete(${className}DTO ${functionName}, Subject subject) {
        ${functionName}.setPrincipal(subject.getPrincipal());
        return Result.success(this.${functionName}Service.delete(${functionName}));
    }
    
    @Post("/query")
    @RequiresPermissions("${moduleName}:${functionName}:query")
    public Result<Page<${className}DTO>> page(${className}DTO query, Parameters param, Subject subject) {
        query.setPrincipal(subject.getPrincipal());
        return Result.success(${functionName}Service.page(query, param));
    }
}